package com.example.java8.streamdemo.streamdemo.DistinctList;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author by KoVaVo
 * @Date 2021-08-26 21:21
 * @Desc: 使用java8的stream的方式对字符串进行简单的去重
 */
public class StringDistinct {

    public static void main(String[] args) {
        ArrayList<String> stringlist = new ArrayList<>();
        stringlist.add("A");
        stringlist.add("B");
        stringlist.add("C");
        stringlist.add("D");
        stringlist.add("E");
        stringlist.add("F");
        stringlist.add("F");
        System.out.println("去重前");
        for (String s : stringlist) {
            System.out.println(s);
        }
        System.out.println("stream方式去重");
        List<String> collect = stringlist.stream().distinct().collect(Collectors.toList());
        for (String s : collect) {
            System.out.println(s);
        }

    }
}
